home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
vmed.arc
/
VMED10.CCC
< prev
next >
Wrap
Text File
|
1985-12-03
|
5KB
|
180 lines
/*
* VMED10/CCC
* virtual memory interface to ED2 editor
*
* made from Ed Ream's ED10 module
*
* created: November 25, 1983 - Jim Kyle
* changed: February 29, 1984 - Jim Kyle
* last changed: March 3-9, 1984 - Jim Kyle
*/
/* data global to this module (must precede #includes)*/
char bufcflag; /* main buffer changed flag */
#include vm /* gets ED defs also */
/* #include vmtrace /* --comment out unless debugging */
t_r() {} /* --comment out if debugging */
/* Clear the main buffer */
bufnew() /* go_top() call moved 3/3/84 */
{ vm_init(); /* initialize work file, etc. */
bufins(0,0); /* set in null line for EOF */
go_top(); /* position to top of work file */
/* indicate no need to save file yet */
bufcflag = NO;
}
/* Insert a line before the current line.
* p points to a line of length n to be inserted.
* Note: n does not include trailing CR.
*/
bufins(p,n) char *p; int n;
{ char temp[MAXLEN2];
t_r("bufins");
n = min(n,MAXLEN);
vm_move(p,temp+2,n); /* move text */
n += 2; /* include size in the count */
putwd(n,temp); /* move it in */
if (Cur_ln > Lltf) /* 3-8-84 at EOF just add it */
ins_btm(temp);
else {
open_hole(n); /* make room */
cpy_in(temp,clad(),n);
}
bufcflag = YES; /* mark file as changed */
return(OK);
}
/* delete the current line */
bufdel()
{ return(bufdeln(1)); }
/* delete n lines, starting with the current line */
bufdeln(n) int n;
{ if (at_eof()) return(OK); /* 3-8-84 do nothing */
vm_abt(n < 0, "bufdeln");
while (n-- && in_txt()) { /* 3-8-84 */
while (Cur_ln > Llcb)
go_nxb();
if (at_eof()) break; /* 3-7-84 */
else {
ln_del(clad());
if (*Lcptr == 0 && Curr) /* dump empty */
rel_blk(Curr);
}
}
bufcflag = YES;
return(OK);
}
/* replace current line with the line that
* p points to. The new line is of length n.
*/
bufrepl(p,n) char *p; int n;
{ return(bufdel()==OK ? bufins(p,n) : ERR); }
/* copy current line into buffer that p points to.
* the maximum size of that buffer is n.
* return k = length of line in the main buffer.
* if k > n then truncate n - k characters and only
* return n characters in the caller's buffer.
*/
bufgetln(p,n) char *p; int n;
{ int k;
/* last line is always null */
if (past_eof()) { /* 3/8/84 - jk */
*p = EOS;
return(0);
}
/* copy line as long as it is not too long */
k = getwd(clad()) - 2;
vm_move(clad()+2,p,min(k,n));
*(p + min(k,n)) = EOS;
return(k);
}
/* return current line number */
bufln()
{ return(Cur_ln); }
/* return YES if the buffer (i.e.. file) has been
* changed since the last time the file was saved.
*/
bufchng()
{ return(bufcflag); }
/* the file has been saved. clear bufcflag */
bufsaved()
{ bufcflag = NO; }
/* return number of lines in the file (excluding null EOF) */
buffree()
{ return(Lltf-1); } /* 3/8/84 - jk */
/* position buffer pointers to start of indicated line */
bufgo(line) int line; /* all new, 3/3/84 */
{ line = max(0, min(line, buffree()));
return(go_to(line));
}
/* move one line closer to front of buffer, i.e., set
* buffer pointers to start of previous line.
*/
bufup()
{ return(go_pvl()); }
/* Move one line closer to end of buffer, i.e.,
* set buffer pointers to start of next line.
*/
bufdn()
{ return(past_eof() ? OK : go_nxl()); } /* 3-9-84 */
/* return true if at bottom of buffer. /* 3-8-84 */
past_eof()
{ return(Cur_ln >= Lltf); }
/* return true if at last text line */
at_eof()
{ return(Cur_ln == Lltf-1); } /* 3-7-84 - jk */
/* return true if within text limits
* (line > 0 and < Lltf) - added 3-8-84 jk
*/
in_txt()
{ return(Cur_ln < Lltf && Cur_ln > 0); }
/* return true if at top of buffer */
bufattop()
{ return(Cur_ln < 2); }
/* put nlines from buffer starting with line topline at
* position topy of the screen.
*/
bufout(topline,topy,nlines) int topline,topy,nlines;
{ int l;
/* remember buffer's state */
l = Cur_ln;
/* write out one line at a time */
while ((nlines--) > 0) {
outxy(0,topy++);
bufoutln(topline++);
}
/* restore buffer's state */
go_to(l);
}
/* print line of main buffer on screen */
bufoutln(line) int line;
{ char temp[MAXLEN2];
go_to(line);
if (in_txt()) { /* 3-8-84 */
bufgetln(temp,MAXLEN2);
fmtsout(temp, 0);
}
outdeol();
}
/* end module vmed10/ccc */